import {
	getToken,
	getUserinfo
} from "@/utils/common"

let apiUrl = import.meta.env.VITE_API_URL;

export function uploadFileH5({
	url,
	data,
}) {
	let requestUrl = ""
	let userInfo = getUserinfo()
	let token = getToken()
	// #ifdef H5
	let env = import.meta.env
	if (env.MODE === 'development') {
		requestUrl = "/baseapi" + url
	} else {
		requestUrl = apiUrl + url
	}
	// #endif
	// #ifndef H5
	requestUrl = apiUrl + url
	// #endif

	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: requestUrl, // default ecn华北的地址，在七牛云中选择对应位置的网址
			name: 'file',
			header: {
				TOKEN: token,
				UID: userInfo.userid
			},
			formData: {
				...data
			},
			complete: (res) => {
				if (res.statusCode === 200) {
					resolve(JSON.parse(res.data))
				} else {
					reject(res.errMsg)
				}
			},
		})
	})


}